package com.link2room.optimus.service.impl;

import com.link2room.common.service.ICommonService;
import com.link2room.optimus.entity.PriceStatic;
import com.link2room.optimus.entity.PriceStaticDay;
import com.link2room.optimus.entity.PriceStaticWeek;
import com.link2room.optimus.service.IStaticPriceService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by sss on 2016/9/1.
 */
@Service("staticPriceService")
@Transactional
public class StaticPriceServiceImpl implements IStaticPriceService {
    @Resource
    private ICommonService commonService;

    @Override
    public void saveOrUpdateBasePrice(String lhotelGroupCode, String lhotelCode,
                                      String rmtype, String priceCode, List<PriceStatic> priceStaticList,
                                      List<PriceStaticWeek> priceStaticWeekList,
                                      List<PriceStaticDay> priceStaticDayList)throws Exception{
        if(priceStaticList!=null) {
            commonService.saveOrUpdateList(priceStaticList);
        }
        if(priceStaticWeekList!=null){
            commonService.saveOrUpdateList(priceStaticWeekList);
        }
        PriceStaticDay query=new PriceStaticDay();
        query.setLhotelGroupCode(lhotelGroupCode);
        query.setLhotelCode(lhotelCode);
        query.setRmtype(rmtype);
        query.setPriceCode(priceCode);
        commonService.deleteAllEQ(PriceStaticDay.class, query);
        if(priceStaticDayList!=null){
            commonService.saveOrUpdateList(priceStaticDayList);
        }
    }

    @Override
    public void dealBasePrice(List<PriceStatic> priceStaticList,
                              List<PriceStaticWeek> priceStaticWeekList,
                              List<PriceStaticDay> priceStaticDayList,
                              Object[] delWeekPriceIds,
                              Object[] delDayPriceIds)throws Exception{
        if(priceStaticList!=null) commonService.saveOrUpdateList(priceStaticList);
        if(priceStaticWeekList!=null)commonService.saveOrUpdateList(priceStaticWeekList);
        if(priceStaticDayList!=null) commonService.saveOrUpdateList(priceStaticDayList);
        if(delWeekPriceIds!=null&&delWeekPriceIds.length>0)commonService.delete(PriceStaticWeek.class, delWeekPriceIds);
        if(delDayPriceIds!=null&&delDayPriceIds.length>0) commonService.delete(PriceStaticDay.class, delDayPriceIds);
    }
}
